package demo513;

import java.io.*;

public class TestFile {
    public  void setData(String filename,String data) throws IOException {


        FileWriter fileWriter = new FileWriter(filename);
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
        bufferedWriter.write(data);
        bufferedWriter.close();

    }
    public void getData(String filename) throws IOException {
        try {
            FileReader fileReader=new FileReader(filename);
            BufferedReader reader=new BufferedReader(fileReader);
            String data;
            while( (data= reader.readLine())!=null) {
                System.out.println(data);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        finally {
            System.out.println("不管是否发生异常都会执行finally里边的代码");
        }

    }
}
